class Solution {
     public int evalRPN(String[] tokens) {
        Deque<Integer> numStack = new LinkedList<>(); // 栈、队列用 LinkedList  堆用 PriorityQueue
        int len = tokens.length;
        for(int i = 0; i < len; i++) {
            String token = tokens[i];
            System.out.println(token);
            if(isNumber(token)) {
                Integer j = Integer.valueOf(token);
                numStack.push(j);
            } else {
                Integer b = numStack.pop();
                Integer a = numStack.pop();
                Integer res = eval(token, a, b);
                numStack.push(res);
            }
        }
        return numStack.pop();
    }

    private boolean isNumber(String token) {
        return !token.equals("+") && !token.equals("-") && !token.equals("*") && !token.equals("/");
    }

    private Integer eval(String operator, Integer a, Integer b) {
        if(operator.equals("+")) return a + b;
        if(operator.equals("-")) return a - b;
        if(operator.equals("*")) return a * b;
        return a / b;
    }
}